package com.handydata.antifraud.port.impl;

import java.util.Objects;

import lombok.extern.log4j.Log4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.handydata.antifraud.dao.RiskRuleDictlinfoBasedataDao;
import com.handydata.antifraud.entity.RiskRuleDictIinfoDao;
import com.handydata.antifraud.port.Arithmetic;
import com.handydata.antifraud.port.RuleEngineInvokers;

@Service
@Log4j
public class ArithmeticImpl implements Arithmetic {
    @Autowired
    private RuleEngineInvokers ruleEngineInvokers;

    @Autowired
    private RiskRuleDictlinfoBasedataDao riskRuleDictlinfoBasedataDao;

    @Override
    public boolean getFlag(String packageName) {
        RiskRuleDictIinfoDao riskRuleDictIinfoDao = new RiskRuleDictIinfoDao();
        riskRuleDictIinfoDao.setPackageName(packageName);
        riskRuleDictIinfoDao.setStatus("1");
        riskRuleDictIinfoDao = riskRuleDictlinfoBasedataDao.queryOne(riskRuleDictIinfoDao);
        if(Objects.isNull(riskRuleDictIinfoDao)){
            log.info("规则配置表没有配置{}规则，请去配置!"+packageName);
            return false;
        }
        if(null == riskRuleDictIinfoDao.getProcessName()){
            log.info("规则决策名称为空，请去配置"+packageName);
            return false;
        }
        if(null == riskRuleDictIinfoDao.getProductCode()){
            log.info("规则产品名称为空，请去配置"+packageName);
            return false;
        }
        if(null == riskRuleDictIinfoDao.getCustTypeCode()){
            log.info("客户类型编号名称为空，请去配置"+packageName);
            return false;
        }
        if(null == riskRuleDictIinfoDao.getProcessDecisionScenario()){
            log.info("授信续约区别码为空，请按照规则配置: 0.授信,1.贷前,2.贷后.默认值");
            return false;
        }
        ruleEngineInvokers.refreshPackage(packageName);
        log.info("开始发起刷新新的规则文件[{}]>>>>>>>>>>>>>>>>>>>>>>>>>>"+packageName);
        return true;
    }
}
